<?php

class Application_Model_Categories extends Zend_Db_Table_Abstract
{

    protected $_name = "kp_categories"; //Ten bang
    protected $_primary = "cat_id"; //Khoa chinh
    protected $db;
    //Cac truong du lieu
    var $cat_id;
    var $cat_slug;
    var $cat_name;
    var $cat_status=0;
    
    //Ham khoi tao
    public function __construct(){
    	$this->db = Zend_Registry::get('db');
    }
    
    //Get all user
    public function getAll($status=-1){
    	$query = $this->db->select();
    	$query->from($this->_name);
    	if($status!=-1)$query->where('cat_status = ?',$status);
    	$query->order(array('cat_name'));
    	return $this->db->fetchAll($query);
    }
    
    //Them mới user
    public function insertCat(){
    	$data = array(
    			'cat_name' => $this->cat_name,
    	        'cat_slug' => $this->cat_slug,
    			'cat_status'=>$this->cat_status,
    	);
    	//var_dump($data); die;
    	return $this->db->insert($this->_name,$data);
    }
    
    public function updateCat(){
    	$data = array(    			
    			'cat_name' => $this->cat_name,
    			'cat_status'=>$this->cat_status,
    	);
    	$where = array('cat_id =?'=>$this->cat_id);
    	//var_dump($data); die;
    	return $this->db->update($this->_name,$data,$where);
    }
    //Xoa theo os_id
    public function deleteID($id){
    	$where = array('cat_id =?'=>$id);
    	return $this->db->delete($this->_name,$where);
    }
}

